﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApFlexParameterController
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Globalization;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

public class CApFlexParameterController
{
  private CUiFLEXCreateCableCmd m_command;
  private const string CABLE_LENGTH = "cableLength";
  private const string CABLE_RADIUS = "cableRadius";
  private const string CABLE_RESOLUTION = "cableResolution";
  private const string CABLE_DENSITY = "cableDensity";
  private const string CABLE_YOUNGS_MODULUS = "cableYoungsModulus";
  private const string CABLE_MAX_TENSION = "cableMaxTesion";
  private const string CABLE_MAX_TWIST = "cableMaxTwistAngle";
  private const string CABLE_MIN_CURVATURE_RADIUS = "cableMinCurvatureRadius";
  private const string CABLE_MAX_CONTACT_FORCE = "cableMaxContactForce";
  private const string IS_PARAMETERS_EXPANDER_OPEN = "isParametersExpanderOpen";
  private const string IS_ATTACHMENTS_EXPANDER_OPEN = "isAttachmentsExpanderOpen";
  private const string CABLE_ATTACHMENT_LOCATION = "cableAttachmentLocation";
  private const string CABLE_ATTACHMENT_LENGTH_FROM_START = "cableAttachmentLengthFromStart";
  private const string CABLE_FULCRUM_LENGTH = "cableFulcrumLength";
  private const string CABLE_START_FULCRUM_LENGTH = "startCableFulcrumLength";
  private const string CABLE_END_FULCRUM_LENGTH = "endCableFulcrumLength";
  private const string CABLE_OSCILLATION = "cableOscillation";
  private const string CABLE_CREATION_MODE = "cableCreatioMode";
  private const string CABLE_IS_MAX_TWIST_ANGLE_LIMITED = "cableIsMaxTwistAngleLimited";
  private const string CABLE_IS_MIN_CURVATURE_RADIUS_LIMITED = "cableIsMinCurvatureRadiusLimited";
  private const string CABLE_IS_MAX_CONTACT_FORCE_LIMITED = "cableIsMaxContactForceLimited";
  private const string CABLE_ROTATING_ROTATION_AXIS = "cableRotatingRotationAxis";
  private const string CABLE_ROTATING_SLIDING_ROTATION_AXIS = "cableRotatingSlidingRotationAxis";
  private const string CABLE_RETRACT_SYSTEM_SPRING_CONSTANT = "cableRetractSystemSpringConstant";
  private const string CABLE_RETRACT_SYSTEM_MIN_RETRACTLENGTH = "cableRetractSystemMinRetractLength";
  private const string CABLE_RETRACT_SYSTEM_MAX_RETRACTLENGTH = "cableRetractSystemMaxRetractLength";
  private const string IS_YOUNGS_MODULUS_OPTIMIZATION_ACTIVATED = "isYoungsModulusOptimizationActivated";
  private const string IS_RADIUS_OPTIMIZATION_ACTIVATED = "isRadiusOptimizationActivated";
  private const string IS_LENGTH_OPTIMIZATION_ACTIVATED = "isLengthOptimizationActivated";
  private double length;
  private double radius;
  private double density;
  private double youngsModulus;
  private double maxTension;
  private double maxTwist;
  private double minCurvatureRadius;
  private double maxContactForce;
  private double fulcrumLength;
  private double oscillation;
  private int resolution;
  private CUiFLEXCreationMode creationMode;
  private double attachmentLengthFromStart;
  private bool isMaxTwistAngleLimited;
  private bool isMinCurvatureRadiusLimited;
  private bool isMaxContactForceLimited;
  private CApFLEXAttachmentLocation attachmentLocation;
  private CApFLEXRotatingAttachmentRotationAxis rotatingRotationAxis;
  private CApFLEXRotatingSlidingAttachmentRotationAxis rotatingSlidingRotationAxis;
  private double retractSystemSpringConstant;
  private double retractSystemMinRetractLength;
  private double retractSystemMaxRetractLength;

  public CApFlexParameterController(CUiFLEXCreateCableCmd command)
  {
    this.m_command = command;
    this.length = 1000.0;
    this.radius = 20.0;
    this.density = 1000.0;
    this.youngsModulus = 1.0;
    this.maxTension = 9.81;
    this.maxTwist = 2.0 * Math.PI;
    this.minCurvatureRadius = 0.0;
    this.maxContactForce = 9.81;
    this.resolution = 1;
    this.attachmentLocation = CApFLEXAttachmentLocation.AlongCable;
    this.attachmentLengthFromStart = 50.0;
    this.fulcrumLength = 0.0;
    this.oscillation = 0.5;
    this.IsParametersExpanderOpen = false;
    this.IsAttachmentsExpanderOpen = false;
    this.isMaxTwistAngleLimited = false;
    this.isMinCurvatureRadiusLimited = false;
    this.isMaxContactForceLimited = false;
    this.rotatingRotationAxis = CApFLEXRotatingAttachmentRotationAxis.X;
    this.rotatingSlidingRotationAxis = CApFLEXRotatingSlidingAttachmentRotationAxis.X;
    this.retractSystemSpringConstant = 100.0;
    this.retractSystemMinRetractLength = 0.0;
    this.retractSystemMaxRetractLength = 400.0;
    this.creationMode = CUiFLEXCreationMode.MANUAL;
    this.IsLengthOptimizationActivated = true;
    this.IsRadiusOptimizationActivated = true;
    this.IsYoungsModulusOptimizationActivated = true;
  }

  public void Save() => this.SaveStorageData();

  public void Load() => this.LoadStorageData();

  public void SaveStorageData()
  {
    TxCommandPrivateDataStorage privateDataStorage = new TxCommandPrivateDataStorage((ITxCommand) this.m_command);
    try
    {
      privateDataStorage.SetIntValue("cableAttachmentLocation", (int) Convert.ToInt16((object) this.AttachmentLocation));
      privateDataStorage.SetStringValue("cableAttachmentLengthFromStart", Convert.ToString(this.AttachmentLengthFromStart));
      privateDataStorage.SetStringValue("cableFulcrumLength", Convert.ToString(this.FulcrumLength));
      privateDataStorage.SetStringValue("cableOscillation", Convert.ToString(this.Oscillation));
      privateDataStorage.SetStringValue("cableLength", Convert.ToString(this.Length));
      privateDataStorage.SetStringValue("cableRadius", Convert.ToString(this.Radius));
      privateDataStorage.SetStringValue("cableResolution", Convert.ToString(this.Resolution));
      privateDataStorage.SetStringValue("cableDensity", Convert.ToString(this.Density));
      privateDataStorage.SetStringValue("cableYoungsModulus", Convert.ToString(this.YoungsModulus));
      privateDataStorage.SetStringValue("cableMaxTesion", Convert.ToString(this.MaxTension));
      privateDataStorage.SetStringValue("cableMaxTwistAngle", Convert.ToString(this.MaxTwist));
      privateDataStorage.SetStringValue("cableMinCurvatureRadius", Convert.ToString(this.MinCurvatureRadius));
      privateDataStorage.SetStringValue("cableMaxContactForce", Convert.ToString(this.MaxContactForce));
      privateDataStorage.SetIntValue("cableResolution", this.resolution);
      privateDataStorage.SetIntValue("cableCreatioMode", (int) Convert.ToInt16((object) this.CreationMode));
      privateDataStorage.SetIntValue("isParametersExpanderOpen", this.IsParametersExpanderOpen ? 1 : 0);
      privateDataStorage.SetIntValue("isAttachmentsExpanderOpen", this.IsAttachmentsExpanderOpen ? 1 : 0);
      privateDataStorage.SetIntValue("cableIsMaxTwistAngleLimited", this.IsMaxTwistAngleLimited ? 1 : 0);
      privateDataStorage.SetIntValue("cableIsMinCurvatureRadiusLimited", this.IsMinCurvatureRadiusLimited ? 1 : 0);
      privateDataStorage.SetIntValue("cableIsMaxContactForceLimited", this.IsMaxContactForceLimited ? 1 : 0);
      privateDataStorage.SetIntValue("cableRotatingRotationAxis", (int) Convert.ToInt16((object) this.RotatingRotationAxis));
      privateDataStorage.SetIntValue("cableRotatingSlidingRotationAxis", (int) Convert.ToInt16((object) this.RotatingSlidingRotationAxis));
      privateDataStorage.SetStringValue("cableRetractSystemSpringConstant", Convert.ToString(this.RetractSystemSpringConstant));
      privateDataStorage.SetStringValue("cableRetractSystemMinRetractLength", Convert.ToString(this.RetractSystemMinRetractLength));
      privateDataStorage.SetStringValue("cableRetractSystemMaxRetractLength", Convert.ToString(this.RetractSystemMaxRetractLength));
      privateDataStorage.SetIntValue("isYoungsModulusOptimizationActivated", this.IsYoungsModulusOptimizationActivated ? 1 : 0);
      privateDataStorage.SetIntValue("isRadiusOptimizationActivated", this.IsRadiusOptimizationActivated ? 1 : 0);
      privateDataStorage.SetIntValue("isLengthOptimizationActivated", this.IsLengthOptimizationActivated ? 1 : 0);
    }
    catch (Exception ex)
    {
      string message = ex.Message;
    }
  }

  public void LoadStorageData()
  {
    TxCommandPrivateDataStorage storage = new TxCommandPrivateDataStorage((ITxCommand) this.m_command);
    int? nullable1 = CApFlexParameterController.LoadRegistryIntValue(storage, "cableAttachmentLocation");
    if (nullable1.HasValue)
      this.AttachmentLocation = (CApFLEXAttachmentLocation) nullable1.Value;
    string str1 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableLength");
    if (str1 != null)
      this.Length = CApFlexParameterController.ConvertStringToDouble(str1);
    string str2 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableAttachmentLengthFromStart");
    if (str2 != null)
      this.AttachmentLengthFromStart = CApFlexParameterController.ConvertStringToDouble(str2);
    string str3 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableFulcrumLength");
    if (str3 != null)
      this.FulcrumLength = CApFlexParameterController.ConvertStringToDouble(str3);
    string str4 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableOscillation");
    if (str4 != null)
      this.Oscillation = CApFlexParameterController.ConvertStringToDouble(str4);
    string str5 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableRadius");
    if (str5 != null)
      this.Radius = CApFlexParameterController.ConvertStringToDouble(str5);
    int? nullable2 = CApFlexParameterController.LoadRegistryIntValue(storage, "cableResolution");
    if (nullable2.HasValue)
      this.Resolution = nullable2.Value;
    nullable2 = CApFlexParameterController.LoadRegistryIntValue(storage, "cableCreatioMode");
    if (nullable2.HasValue)
      this.CreationMode = (CUiFLEXCreationMode) nullable2.Value;
    nullable2 = CApFlexParameterController.LoadRegistryIntValue(storage, "isParametersExpanderOpen");
    if (nullable2.HasValue)
      this.IsParametersExpanderOpen = nullable2.Value == 1;
    nullable2 = CApFlexParameterController.LoadRegistryIntValue(storage, "isAttachmentsExpanderOpen");
    if (nullable2.HasValue)
      this.IsAttachmentsExpanderOpen = nullable2.Value == 1;
    nullable2 = CApFlexParameterController.LoadRegistryIntValue(storage, "cableIsMaxTwistAngleLimited");
    if (nullable2.HasValue)
      this.isMaxTwistAngleLimited = nullable2.Value == 1;
    nullable2 = CApFlexParameterController.LoadRegistryIntValue(storage, "cableIsMinCurvatureRadiusLimited");
    if (nullable2.HasValue)
      this.isMinCurvatureRadiusLimited = nullable2.Value == 1;
    nullable2 = CApFlexParameterController.LoadRegistryIntValue(storage, "cableIsMaxContactForceLimited");
    if (nullable2.HasValue)
      this.isMaxContactForceLimited = nullable2.Value == 1;
    string str6 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableDensity");
    if (str6 != null)
      this.Density = CApFlexParameterController.ConvertStringToDouble(str6);
    string str7 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableYoungsModulus");
    if (str7 != null)
      this.YoungsModulus = CApFlexParameterController.ConvertStringToDouble(str7);
    string str8 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableMaxTesion");
    if (str8 != null)
      this.MaxTension = CApFlexParameterController.ConvertStringToDouble(str8);
    string str9 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableMaxTwistAngle");
    if (str9 != null)
      this.MaxTwist = CApFlexParameterController.ConvertStringToDouble(str9);
    string str10 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableMinCurvatureRadius");
    if (str10 != null)
      this.MinCurvatureRadius = CApFlexParameterController.ConvertStringToDouble(str10);
    string str11 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableMaxContactForce");
    if (str11 != null)
      this.MaxContactForce = CApFlexParameterController.ConvertStringToDouble(str11);
    nullable2 = CApFlexParameterController.LoadRegistryIntValue(storage, "cableRotatingRotationAxis");
    if (nullable2.HasValue)
      this.RotatingRotationAxis = (CApFLEXRotatingAttachmentRotationAxis) nullable2.Value;
    nullable2 = CApFlexParameterController.LoadRegistryIntValue(storage, "cableRotatingSlidingRotationAxis");
    if (nullable2.HasValue)
      this.RotatingSlidingRotationAxis = (CApFLEXRotatingSlidingAttachmentRotationAxis) nullable2.Value;
    string str12 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableRetractSystemSpringConstant");
    if (str12 != null)
      this.RetractSystemSpringConstant = CApFlexParameterController.ConvertStringToDouble(str12);
    string str13 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableRetractSystemMinRetractLength");
    if (str13 != null)
      this.RetractSystemMinRetractLength = CApFlexParameterController.ConvertStringToDouble(str13);
    string str14 = CApFlexParameterController.LoadRegistryStringValue(storage, "cableRetractSystemMaxRetractLength");
    if (str14 != null)
      this.RetractSystemMaxRetractLength = CApFlexParameterController.ConvertStringToDouble(str14);
    nullable2 = CApFlexParameterController.LoadRegistryIntValue(storage, "isYoungsModulusOptimizationActivated");
    if (nullable2.HasValue)
      this.IsYoungsModulusOptimizationActivated = nullable2.Value == 1;
    nullable2 = CApFlexParameterController.LoadRegistryIntValue(storage, "isRadiusOptimizationActivated");
    if (nullable2.HasValue)
      this.IsRadiusOptimizationActivated = nullable2.Value == 1;
    nullable2 = CApFlexParameterController.LoadRegistryIntValue(storage, "isLengthOptimizationActivated");
    if (!nullable2.HasValue)
      return;
    this.IsLengthOptimizationActivated = nullable2.Value == 1;
  }

  private static double ConvertStringToDouble(string str)
  {
    str = str.Replace(".", ",");
    return Convert.ToDouble(str, (IFormatProvider) new NumberFormatInfo()
    {
      NumberDecimalSeparator = ",",
      NumberGroupSeparator = "."
    });
  }

  public CApFLEXAttachmentLocation AttachmentLocation
  {
    get => this.attachmentLocation;
    set => this.attachmentLocation = value;
  }

  public double AttachmentLengthFromStart
  {
    get => this.attachmentLengthFromStart;
    set => this.attachmentLengthFromStart = value;
  }

  public double Length
  {
    get => this.length;
    set => this.length = value;
  }

  public double FulcrumLength
  {
    get => this.fulcrumLength;
    set => this.fulcrumLength = value;
  }

  public double Oscillation
  {
    get
    {
      if (this.oscillation > 1.0)
        this.oscillation /= 100.0;
      return this.oscillation;
    }
    set => this.oscillation = value;
  }

  public double Radius
  {
    get => this.radius;
    set => this.radius = value;
  }

  public double Density
  {
    get => this.density;
    set => this.density = value;
  }

  public double YoungsModulus
  {
    get => this.youngsModulus;
    set => this.youngsModulus = value;
  }

  public double MaxTension
  {
    get => this.maxTension;
    set => this.maxTension = value;
  }

  public double MaxTwist
  {
    get => this.maxTwist;
    set => this.maxTwist = value;
  }

  public double MinCurvatureRadius
  {
    get => this.minCurvatureRadius;
    set => this.minCurvatureRadius = value;
  }

  public double MaxContactForce
  {
    get => this.maxContactForce;
    set => this.maxContactForce = value;
  }

  public int Resolution
  {
    get => this.resolution;
    set => this.resolution = value;
  }

  public CUiFLEXCreationMode CreationMode
  {
    get => this.creationMode;
    set => this.creationMode = value;
  }

  public bool IsParametersExpanderOpen { get; set; }

  public bool IsYoungsModulusOptimizationActivated { get; set; }

  public bool IsRadiusOptimizationActivated { get; set; }

  public bool IsLengthOptimizationActivated { get; set; }

  public bool IsAttachmentsExpanderOpen { get; set; }

  public bool IsMaxTwistAngleLimited
  {
    get => this.isMaxTwistAngleLimited;
    set => this.isMaxTwistAngleLimited = value;
  }

  public bool IsMinCurvatureRadiusLimited
  {
    get => this.isMinCurvatureRadiusLimited;
    set => this.isMinCurvatureRadiusLimited = value;
  }

  public bool IsMaxContactForceLimited
  {
    get => this.isMaxContactForceLimited;
    set => this.isMaxContactForceLimited = value;
  }

  public CApFLEXRotatingAttachmentRotationAxis RotatingRotationAxis
  {
    get => this.rotatingRotationAxis;
    set => this.rotatingRotationAxis = value;
  }

  public CApFLEXRotatingSlidingAttachmentRotationAxis RotatingSlidingRotationAxis
  {
    get => this.rotatingSlidingRotationAxis;
    set => this.rotatingSlidingRotationAxis = value;
  }

  public double RetractSystemSpringConstant
  {
    get => this.retractSystemSpringConstant;
    set => this.retractSystemSpringConstant = value;
  }

  public double RetractSystemMinRetractLength
  {
    get => this.retractSystemMinRetractLength;
    set => this.retractSystemMinRetractLength = value;
  }

  public double RetractSystemMaxRetractLength
  {
    get => this.retractSystemMaxRetractLength;
    set => this.retractSystemMaxRetractLength = value;
  }

  public static int? LoadRegistryIntValue(TxCommandPrivateDataStorage storage, string valueName)
  {
    int? nullable1 = new int?();
    int? nullable2;
    try
    {
      nullable2 = new int?(storage.GetIntValue(valueName));
    }
    catch (TxCommandPrivateDataValueNotStoredException ex)
    {
      nullable2 = new int?();
    }
    return nullable2;
  }

  public static string LoadRegistryStringValue(
    TxCommandPrivateDataStorage storage,
    string valueName)
  {
    try
    {
      return storage.GetStringValue(valueName);
    }
    catch (TxCommandPrivateDataValueNotStoredException ex)
    {
      return (string) null;
    }
  }
}
